<!DOCTYPE html>
<html>
<head>
    <meta charset=UTF-8>
    <title>Tomcat WebSocket Chat</title>
    <script>
        if (window.WebSocket) {
            console.info('this browser supports websocket!');

        } else {
            console.info('this browser does not support websocket');
        }
        var ws = new WebSocket("ws://localhost:8080/test-websocket/websockettest?a=1");
        ws.onopen = function () {
            console.info('open')
        };
        ws.onmessage = function (message) {
            document.getElementById("chatlog").textContent += message.data + "\n";
        };
        function postToServer() {
            var messageObject = {
                msg: document.getElementById("msg").value,
                houseId: document.getElementById("house").value
            };
            console.info(messageObject)
            ws.send(JSON.stringify(messageObject));
            document.getElementById("msg").value = "";
        }
        function closeConnect() {
            ws.close();
        }
    </script>
</head>
<body>
<textarea id="chatlog" readonly rows="10" cols="50"></textarea><br/>
<input id="msg" type="text"/>
<select id="house">
    <option value=1>房间1</option>
    <option selected="selected" value=2>房间2</option>
</select>
<button onClick="postToServer()">Send</button>
<button onClick="closeConnect()">End</button>
</body>
</html>